﻿-- =============================================
-- Generate Static Data Script Template
-- =============================================

-- Generate Markets

DECLARE @PreOpen time(0);
DECLARE @Open time(0);
DECLARE @Closing time(0);
DECLARE @Closed time(0);
DECLARE @Name nvarchar(128);

SET @PreOpen = '08:30:00';
SET @Open = '09:00:00';
SET @Closing = '17:30:00';
SET @Closed = '17:40:00';
SET @Name = 'BME';
INSERT INTO [dbo].[ExchangeMarkets] VALUES (@Name, @PreOpen ,@Open ,@Closing ,@Closed)

SET @PreOpen = '07:30:00';
SET @Open = '08:00:00';
SET @Closing = null;
SET @Closed = '22:00:00';
SET @Name = 'Eurex';
INSERT INTO [dbo].[ExchangeMarkets] VALUES (@Name, @PreOpen ,@Open ,@Closing ,@Closed)

SET @PreOpen = '07:30:00';
SET @Open = '08:00:00';
SET @Closing = null;
SET @Closed = '22:15:00';
SET @Name = 'Globex';
INSERT INTO [dbo].[ExchangeMarkets] VALUES (@Name, @PreOpen ,@Open ,@Closing ,@Closed)

-- Generate Groups
DECLARE @GroupName nvarchar(128);
DECLARE @MarketName nvarchar(128);
DECLARE @MarketId smallint;

SET @GroupName = 'Ibex35';
SET @MarketName = 'BME';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

-- Obsolete
SET @GroupName = 'Futures';
SET @MarketName = 'BME';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'ContinuousMarket';
SET @MarketName = 'BME';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'MEFFFutures';
SET @MarketName = 'BME';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'EUREXFutures';
SET @MarketName = 'Eurex';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'OtherIndexFutures';
SET @MarketName = 'Globex';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'EnergyAndMaterialsFutures';
SET @MarketName = 'Globex';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'CurrencyFutures';
SET @MarketName = 'Globex';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

SET @GroupName = 'EuroStoxx50';
SET @MarketName = 'BME';
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
INSERT INTO [StockGroups] VALUES (@GroupName,@MarketId);

-- Generate Market Holidays
DECLARE @Holiday datetime

SET @MarketName = 'BME'
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
SET @Holiday = '4/6/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '4/9/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '5/1/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/25/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/26/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @MarketName = 'Eurex'
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
SET @Holiday = '4/6/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '4/9/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '5/1/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/24/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/25/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/26/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/31/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @MarketName = 'Globex'
SET @MarketId = (SELECT Id FROM [dbo].[ExchangeMarkets] WHERE Name = @MarketName);
SET @Holiday = '1/13/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '2/17/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '4/6/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '4/9/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '7/3/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '8/31/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '10/5/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '11/12/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '11/23/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/24/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/25/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);

SET @Holiday = '12/31/2012'
INSERT INTO [ExchangeMarketHolidays] VALUES (@MarketId,@Holiday);